#include "PrecompiledHeader.h"
#include "Music.h"

/*--------------------------------------------------------------------------*/

Music::Music(const std::string& filename) :
	IResource("music:" + filename)
{
	this->m_path = filename;
	this->m_music = NULL;
}

/*--------------------------------------------------------------------------*/

Music::~Music()
{
	if (this->m_music != NULL)
	{
		Mix_FreeMusic(this->m_music);
		this->m_music = NULL;
	}
}

/*--------------------------------------------------------------------------*/

Mix_Music* Music::GetMusic() const
{
	return this->m_music;
}

/*--------------------------------------------------------------------------*/

void Music::Reload()
{
	if (this->m_music != NULL)
	{
		Mix_FreeMusic(this->m_music);
		this->m_music = NULL;
	}

	this->m_music = Mix_LoadMUS(this->GetPath().c_str());

	AssertLogE(this->m_music == NULL, "Can not load file: %s", this->m_path);
}

/*--------------------------------------------------------------------------*/

const std::string& Music::GetPath() const
{
	return this->m_path;
}

/*--------------------------------------------------------------------------*/

void Music::SetPath(const std::string& path)
{
	this->m_path = path;
}

/*--------------------------------------------------------------------------*/